package jmine.tec.rpc.common.serialization.json;

import jmine.tec.json.JSON;
import jmine.tec.json.JSONBoolean;

/**
 * Conversor de JSON para Java e vice-versa
 * 
 * @author lundberg
 */
public class JSONBooleanConverter implements JSONConverterStrategy {

    /**
     * {@inheritDoc}
     */
    public boolean matchesJava(Object object) {
        return object instanceof Boolean || object.getClass() == boolean.class;
    }

    /**
     * {@inheritDoc}
     */
    public boolean matchesJSON(JSON json) {
        return json instanceof JSONBoolean;
    }

    /**
     * {@inheritDoc}
     */
    public Object toJava(JSONConversionContext context, JSON json) {
        return ((JSONBoolean) json).booleanValue();
    }

    /**
     * {@inheritDoc}
     */
    public JSON toJSON(JSONConversionContext context, Object object) {
        return JSONBoolean.fromBoolean((Boolean) object);
    }
}
